package com.list.wildlife.selector;

import java.io.InputStream;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.FileManager;
import com.list.wildlife.util.Log;

public class OWLParser {
	private String defaultParser = "owlParser";
	private String defaultFileName = "./list_lsl/list_lsl.owl";
	private Model model;
	public static boolean debug = false;
	
	private String owlFile;
	
	public OWLParser(String owlFile) {
		this.owlFile = debug ? defaultFileName : owlFile;
		model = getModelFromFile(this.owlFile);
		Log.log(Log.DEFAULT, "Creating parser for rdf/owl file: " + owlFile);
		Log.log(Log.DEFAULT, "Using Parser : " + defaultParser);
	}
	
	/**
	 * Read rdf File as parameter and return Model !!!
	 * @param fileName
	 * @return
	 */
	private Model getModelFromFile(String fileName) {
		Model model = ModelFactory.createDefaultModel();
		InputStream inputStream = FileManager.get().open(fileName);
		if(inputStream == null) {
			Log.log(Log.DETAIL, "File: [" + fileName +"] not found! \n");
		}
		model.read(inputStream, fileName);
		Log.log(Log.DETAIL, "rdf File [" + fileName +"] is loaded!!! \n");
		return model;
	}
	
	public Model model() {
		return this.model;
	}
}
